@import '../../theme';
@import '../../mixins';
@import '~bootstrap/scss/forms';
@import '~bootstrap/scss/custom-forms';

.form-control {
  margin-bottom: spacer(1);
  &:focus {
    border-color: theme-color('secondary');
    box-shadow: none;
    -webkit-box-shadow: none;
  }
}

.invalid-feedback {
  text-align: left;
  &::before {
    content: '!';
    color: theme-color('inverse');
    text-align: center;
    border-radius: 50%;
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: theme-color('danger');
    margin-right: 6px;
    font-weight: $font-weight-bold;
  }
  &:focus {
    box-shadow: none;
    -webkit-box-shadow: none;
  }
}

.is-invalid {
  color: theme-color('danger');
}

input[type='checkbox'],
input[type='radio'] {
  height: 22px;
  width: 22px;
  vertical-align: middle;
  cursor: pointer;
  line-height: 1.42857;
  appearance: none;
  -webkit-appearance: textfield;
  -moz-appearance: textfield;
  font-size: inherit;
  box-sizing: border-box;
  outline: none;
  border-style: solid;
  border-width: 1px;
  position: absolute;
  margin-top: 0.3rem;
  margin-left: -1.25rem;
}

.form-check {
  margin-bottom: 18px;

  label {
    font-weight: $font-weight-normal;
  }

  .form-check-label {
    display: inline-block;
    padding-left: 0.75rem;
    position: relative;
    top: 4px;
  }

  input + .form-check-label {
    color: theme-color('text');

    &::after {
      content: none;
    }
  }

  input:disabled + .form-check-label {
    color: theme-color('light');
  }

  input[role='checkbox'],
  input[role='radio'] {
    display: inline-block;

    &:focus {
      box-shadow: 0px 0px 0px 3px theme-color('light');
      border-color: theme-color('secondary');
    }
  }

  input[type='checkbox'] {
    border: 2px solid theme-color('light');
    border-radius: 5px;

    &:checked {
      font-style: normal;
      border: var(--cx-g-color-primary, theme-color('primary'));
      background-color: var(--cx-g-color-primary, theme-color('primary'));

      &::after {
        color: theme-color('inverse');
        position: absolute;
        content: '';
        display: inline-block;
        height: 6px;
        width: 9px;
        top: 7px;
        left: 6px;
        border-left: 2px solid theme-color('inverse');
        border-bottom: 2px solid theme-color('inverse');
        transform: rotate(-45deg);
      }
    }
  }
}

.form-control[type='text'] {
  &:focus {
    background-color: theme-color('background');
    box-shadow: none;
    -webkit-box-shadow: none;
  }
}

input[type='radio'] {
  border-radius: 50%;
  display: inline-block;
  border: 2px solid theme-color('light');
  position: absolute;

  &::after {
    content: '';
    position: absolute;
    display: inline-block;
    height: 10px;
    width: 10px;
    border-radius: 50%;
    background-color: theme-color('inverse');
    left: 4px;
    top: 4px;
  }
  &:checked {
    border-color: var(--cx-g-color-primary, theme-color('primary')) !important;
    background-color: theme-color('inverse');

    &::after {
      @include var-color('background-color', 'primary');
    }
  }
}

.form-toggle {
  position: relative;
  display: inline-block;
  width: 88px;
  height: 40px;
}

.form-toggle-input {
  display: none;
}

.form-toggle__switch {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: theme-color('light');
  -webkit-transition: 0.4s;
  transition: 0.4s;
  border-radius: 34px;

  &:before {
    position: absolute;
    content: '';
    height: 32px;
    width: 32px;
    left: 4px;
    bottom: 4px;
    background-color: theme-color('inverse');
    -webkit-transition: 0.4s;
    transition: 0.4s;
    border-radius: 50%;
  }
}

input[role='switch']:checked + .form-toggle__switch {
  background-color: theme-color('primary');
  &:before {
    left: calc(100% - 5px);
    transform: translateX(-100%);
  }

  &:focus + .form-toggle__switch {
    box-shadow: 0 0 1px theme-color('info');
  }
}

.toggle-on,
.toggle-off {
  color: theme-color('inverse');
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  @include type('5', 'bold');
}

.toggle-on {
  display: none;
  left: 30%;
}

.toggle-off {
  right: -7%;
}

input:checked + .form-toggle__switch {
  .toggle-on {
    display: block;
  }

  .toggle-off {
    display: none;
  }
}

label {
  display: block;
  .label-content {
    display: block;
    margin-bottom: $label-margin-bottom;
    &.bold {
      font-weight: $font-weight-semi;
    }
  }
}

.form-message {
  font-size: $small-font-size;
  &--danger {
    color: theme-color('danger');
  }
}

.ng-select.ng-select-single,
.ng-select {
  .ng-dropdown-panel {
    .ng-dropdown-panel-items {
      .ng-option.ng-option-marked {
        background-color: theme-color('light');
      }
    }
  }

  .ng-arrow-wrapper {
    .ng-arrow {
      border-color: theme-color('text') transparent transparent;
      border-style: solid;
      border-width: 5px 5px 2.5px;
    }
  }

  .ng-select-container {
    padding: $input-padding-y 0;
    line-height: 1.6;
    height: unset;
  }
}
